﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

public abstract class AnimateComponentFloat<T> : AnimateComponentFloatBase
{
    public AnimationCurve curve;
    public T target;
    public bool unscaledTime;

    protected AnimateComponentFloat()
    {
        this.curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
    }

    [DebuggerHidden]
    private IEnumerator AnimateValue(AnimationCurve curve, Action<float> onGetValue)
    {
        return new <AnimateValue>c__Iterator12<T> { onGetValue = onGetValue, curve = curve, <$>onGetValue = onGetValue, <$>curve = curve, <>f__this = (AnimateComponentFloat<T>) this };
    }

    private void OnEnable()
    {
        this.target = base.GetComponent<T>();
        if (this.target != null)
        {
            base.StartCoroutine(this.AnimateValue(this.curve, v => this.SetValue(v)));
        }
    }

    protected abstract void SetValue(float value);

    public System.Type targetType
    {
        get
        {
            return typeof(T);
        }
    }

    [CompilerGenerated]
    private sealed class <AnimateValue>c__Iterator12 : IDisposable, IEnumerator, IEnumerator<object>
    {
        internal object $current;
        internal int $PC;
        internal AnimationCurve <$>curve;
        internal Action<float> <$>onGetValue;
        internal AnimateComponentFloat<T> <>f__this;
        internal float <deltaTime>__2;
        internal float <duration>__1;
        internal float <timer>__0;
        internal AnimationCurve curve;
        internal Action<float> onGetValue;

        [DebuggerHidden]
        public void Dispose()
        {
            this.$PC = -1;
        }

        public bool MoveNext()
        {
            uint num = (uint) this.$PC;
            this.$PC = -1;
            switch (num)
            {
                case 0:
                    if ((this.onGetValue != null) && (this.curve.keys.Length != 0))
                    {
                        this.<timer>__0 = 0f;
                        this.<duration>__1 = ((this.curve.postWrapMode != WrapMode.Once) && (this.curve.postWrapMode != WrapMode.Once)) ? -1f : this.curve.keys.Last<Keyframe>().time;
                        break;
                    }
                    goto Label_012C;

                case 1:
                    break;

                default:
                    goto Label_012C;
            }
            while ((this.<duration>__1 < 0f) || (this.<timer>__0 <= this.<duration>__1))
            {
                this.<deltaTime>__2 = !this.<>f__this.unscaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
                this.<timer>__0 += this.<deltaTime>__2;
                this.onGetValue(this.curve.Evaluate(this.<timer>__0));
                this.$current = null;
                this.$PC = 1;
                return true;
            }
            this.$PC = -1;
        Label_012C:
            return false;
        }

        [DebuggerHidden]
        public void Reset()
        {
            throw new NotSupportedException();
        }

        object IEnumerator<object>.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }

        object IEnumerator.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }
    }
}

